package com.samehope.ar.service.impl;

import com.samehope.ar.entity.SysUserRole;
import com.samehope.ar.mapper.SysUserRoleMapper;
import com.samehope.ar.service.ISysUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.samehope.ar.util.SessionUtil;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 用户项目角色 服务实现类
 * </p>
 *
 * @author Zhang Luo
 * @since 2019-12-23
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {

    /**
     * 创建信息对象
     * @param userId
     * @param roleId
     * @param createDate
     * @return
     */
    @Override
    public SysUserRole createObject(Long userId, Long roleId, LocalDateTime createDate) {
        SysUserRole userRole = new SysUserRole();
        userRole.setCompanyId(SessionUtil.getCompanyId());
        userRole.setProjectId(SessionUtil.getProjectId());
        userRole.setUserId(userId);
        userRole.setRoleId(roleId);
        userRole.setCreateBy(SessionUtil.getUserId());
        userRole.setCreateDate(createDate);
        return userRole;
    }

    /**
     * 查找用户的管理角色关系
     * @param userId
     * @return
     */
    @Override
    public List<SysUserRole> findManageUserRole(Long userId) {
        return this.baseMapper.findManageUserRoleByProjectAndUser(SessionUtil.getProjectId(), userId);
    }

    /**
     * 获取所有的项目用户角色
     * @param userId
     * @return
     */
    @Override
    public List<SysUserRole> findRolesByUser(Long userId) {
        return this.baseMapper.findRolesByProjectAndUserId(SessionUtil.getProjectId(), userId);
    }
}
